package com.tommy.jiami.ui.dialog;

import android.app.*;
import android.view.*;
import android.os.*;
import com.tommy.jiami.view.*;
import android.widget.*;
import com.tommy.jiami.utils.*;
import com.tommy.jiami.*;

public class LockDialog extends DialogFragment
{
	OnLockSuccessListener listener;
	LockPatternView lockView;
	String userPwd;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		getDialog().setTitle(R.string.write_password);
		LinearLayout layout=new LinearLayout(getActivity());
		lockView=new LockPatternView(getActivity());
		int width=Utils.getScreenWidth();
		lockView.setLayoutParams(new ViewGroup.LayoutParams(width,width));
		userPwd=Utils.getUserPassword();
		lockView.setOnPatternChangeListener(new LockPatternView.OnPatternChangeListener(){
			@Override
			public void onPatternChange(String result)
			{
				if(result!=null&&result.equals(userPwd)&&listener!=null){
					listener.onSuccess();
					getDialog().cancel();
				}else{
					lockView.error();
				}
			}	
		});
		layout.addView(lockView);
		return layout;
	}
	
	public void setOnLockSuccessListener(OnLockSuccessListener listener){
		this.listener=listener;
	}
	
	public interface OnLockSuccessListener{
		public void onSuccess();
	}
}
